﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace CLEXA.DataContracts
{
    [DataContract]
    public class QueryData
    {
        [DataMember]
        private readonly string tableName;
        [DataMember]
        private readonly int maxResultCount;
        [DataMember]
        private readonly List<string> groupByColumns;
        private ReadOnlyCollection<string> groupByColumnsReadOnly;
        [DataMember]
        private readonly List<AggregateData> aggregates;
        private ReadOnlyCollection<AggregateData> aggregatesReadOnly;

        public string TableName
        {
            get { return tableName; }
        } 

        public int MaxResultCount
        {
            get { return maxResultCount; }
        }

        public ReadOnlyCollection<string> GroupByColumns
        {
            get
            {
                if (groupByColumnsReadOnly == null)
                {
                    groupByColumnsReadOnly = new ReadOnlyCollection<string>(groupByColumns);
                }
                return groupByColumnsReadOnly;
            }
        } 

        public ReadOnlyCollection<AggregateData> Aggregates
        {
            get
            {
                if (aggregatesReadOnly == null)
                {
                    aggregatesReadOnly = new ReadOnlyCollection<AggregateData>(aggregates);
                }
                return aggregatesReadOnly;
            }
        }

        public QueryData(string tableName, int maxResultCount, IEnumerable<string> groupByColumns, IEnumerable<AggregateData> aggregates)
        {
            this.tableName = tableName;
            this.maxResultCount = maxResultCount;
            this.groupByColumns = groupByColumns.ToList();
            this.aggregates = aggregates.ToList();
        }
    }
}
